package com.hua.demo.edu.controller;


import com.hua.R;
import com.hua.demo.edu.entity.Course;
import com.hua.demo.edu.entity.CourseDescription;
import com.hua.demo.edu.entity.vo.CourseInfoVo;
import com.hua.demo.edu.entity.vo.CoursePublishVo;
import com.hua.demo.edu.service.CourseDescriptionService;
import com.hua.demo.edu.service.CourseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author huazi
 * @since 2021-11-24
 */
@RestController
@RequestMapping("/edu/course")
//@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private CourseDescriptionService courseDescriptionService;
    @GetMapping("getcourselist")
    public R getcourselist(){
        List<Course> list = courseService.list(null);
        return R.ok().data("list",list);
    }
    @PostMapping("addcourseinfo")
    public R addcourseinfo(@RequestBody CourseInfoVo courseInfoVo){
        courseService.savecourseinfo(courseInfoVo);
        return R.ok();
    }
    @GetMapping("getcourseinfo/{courseid}")
    public R getcourseinfo(@PathVariable String courseid){
      CourseInfoVo courseInfoVo=courseService.getcoursebyid(courseid);
      return R.ok().data("courseinfo",courseInfoVo);

    }
    @PostMapping("updatecourseinfo")
    public R updatecourseinfo(@RequestBody CourseInfoVo courseInfoVo){
        courseService.updatecourseinfo(courseInfoVo);
        return R.ok();
    }

    @PostMapping("getPublishCourseInfo/{id}")
    public R getpubliccourseinfo(@PathVariable String id){
        CoursePublishVo getcoursepublicvo = courseService.getcoursepublicvo(id);
        return R.ok().data("coursepublicvo",getcoursepublicvo);

    }


}

